// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OptionViewModel.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="OptionViewModel" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Modules.Core.Management.ViewModel
{
    using System;
    using System.Collections.ObjectModel;
    using System.Diagnostics.Contracts;
    using System.Windows.Input;
    using System.Windows.Media;

    using Hisaab.Business.Interfaces;
    using Hisaab.Client.Common.BaseClasses;
    using Hisaab.Client.Common.Services;
    using Hisaab.Common;

    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.ServiceLocation;

    /// <summary>
    /// Defines the <seealso cref="OptionViewModel"/> type.
    /// </summary>
    public class OptionViewModel : ViewModelBase
    {
        /// <summary>
        /// Member variable _userManager
        /// </summary>
        private readonly IUserManager _userManager;

        /// <summary>
        /// Member variable _session
        /// </summary>
        private readonly ISession _session;

        /// <summary>
        /// Member variable _message
        /// </summary>
        private string _message;

        /// <summary>
        /// Member variable _messageColor
        /// </summary>
        private Brush _messageColor;

        /// <summary>
        /// Member variable _currencySymbol
        /// </summary>
        private Currency _currencySymbol;

        /// <summary>
        /// Member variable _updateCommand
        /// </summary>
        private DelegateCommand _updateCommand;

        /// <summary>
        /// Initializes a new instance of the <see cref="OptionViewModel"/> class.
        /// </summary>
        public OptionViewModel()
            : this(ServiceLocator.Current.GetInstance<IUserManager>(), ServiceLocator.Current.GetInstance<ISession>())
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OptionViewModel"/> class.
        /// </summary>
        /// <param name="userManager">The user manager.</param>
        /// <param name="session">The session.</param>
        public OptionViewModel(IUserManager userManager, ISession session)
        {
            Contract.Requires<ArgumentNullException>(userManager != null);
            Contract.Requires<ArgumentNullException>(session != null);

            _userManager = userManager;
            _session = session;

            MessageColor = Brushes.Green;
        }

        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        /// <value>
        /// The message.
        /// </value>
        public string Message
        {
            get
            {
                return _message;
            }

            set
            {
                RaisePropertyChangingEvent("Message");
                _message = value;
                RaisePropertyChangedEvent("Message");
            }
        }

        /// <summary>
        /// Gets or sets the color of the message.
        /// </summary>
        /// <value>
        /// The color of the message.
        /// </value>
        public Brush MessageColor
        {
            get
            {
                return _messageColor;
            }

            set
            {
                RaisePropertyChangingEvent("MessageColor");
                _messageColor = value;
                RaisePropertyChangedEvent("MessageColor");
            }
        }

        /// <summary>
        /// Gets or sets the currency symbols.
        /// </summary>
        /// <value>
        /// The currency symbols.
        /// </value>
        public ObservableCollection<KeyValue<string, string>> CurrencySymbols { get; set; }

        /// <summary>
        /// Gets or sets the secret question.
        /// </summary>
        /// <value>
        /// The secret question.
        /// </value>
        public Currency CurrencySymbol
        {
            get
            {
                return _currencySymbol;
            }

            set
            {
                RaisePropertyChangingEvent("CurrencySymbol");
                _currencySymbol = value;
                RaisePropertyChangedEvent("CurrencySymbol");
            }
        }

        /// <summary>
        /// Gets the change password command.
        /// </summary>
        public ICommand UpdateCommand
        {
            get
            {
                if (_updateCommand == null)
                {
                    _updateCommand = new DelegateCommand(OnUpdateOptions);
                }

                return _updateCommand;
            }
        }

        /// <summary>
        /// Called when [update options].
        /// </summary>
        public void OnUpdateOptions()
        {
            // _userManager.SetCurrencySymbol(_session.LoggedUser, CurrencySymbol);
            Message = "Options saved successfully. You might need to restart application to get some setting applied.";
        }
    }
}